/*============================================================================*/
/*                   CONTINENTAL AUTOMOTIVE SYSTEMS                           */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* name:            HAL_selector.c
* version:         1.0
* created_by:      Continental
* date_created:    June 7 2013
*=============================================================================*/
/* DESCRIPTION : Source file for abstraction layer for SELECTOR               */
/*============================================================================*/
/* FUNCTION COMMENT : Source file abstraction layer for SELECTOR              */
/*                                                                            */
/*============================================================================*/
/*                               OBJECT HISTORY                               */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1.0      | 07/jun/2013 |                               | Continental      */
/* Initial version for the Lab 2 using Freescale Bolero micro.                */
/*============================================================================*/

#include "sysinit.h"
#include "HAL_selector.h"
#include "MAL_ioapi.h"


T_UBYTE HAL_selector_GetValue(void)
{
	T_UBYTE selector_value;
	
	/*
	SELECTOR_OFF,
	SELECTOR_AUTO,
	SELECTOR_PARKLAMPS,
	SELECTOR_HEADLAMPS
	*/
	
	selector_value = HAL_selector_ReadButton(SELECTOR1);
	if(selector_value == 0)
	{
		return SELECTOR_OFF;
	}
	
	selector_value = HAL_selector_ReadButton(SELECTOR2);
	if(selector_value == 0)
	{
		return SELECTOR_AUTO;
	}

	selector_value = HAL_selector_ReadButton(SELECTOR3);
	if(selector_value == 0)
	{
		return SELECTOR_PARKLAMPS;
	}
	
	selector_value = HAL_selector_ReadButton(SELECTOR4);
	if(selector_value == 0)
	{
		return SELECTOR_HEADLAMPS;
	}
	
	return 255;
}

void HAL_selector_Init(void)
{
	IO_SetPinAsInput(SELECTOR1);     /* Program the drive enable pin of S1  (PE0)  as input*/
	IO_SetPinAsInput(SELECTOR2);     /* Program the drive enable pin of S2  (PE1)  as input*/
	IO_SetPinAsInput(SELECTOR3);     /* Program the drive enable pin of S3  (PE2)  as input*/
	IO_SetPinAsInput(SELECTOR4);     /* Program the drive enable pin of S4  (PE3)  as input*/			
}

T_UBYTE HAL_selector_ReadButton(T_UBYTE selector)
{
	return IO_PinRead(selector);
}